package com.leonzx.base.controller.userpermission;

import com.leonzx.base.controller.base.BaseController;
import com.leonzx.base.entity.system.Role;
import com.leonzx.base.service.system.RoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author:张勇
 * @Description:
 * @Date: 2018-06-08 15:15
 */
@Controller
@RequestMapping("/role")
public class RoleController extends BaseController {
    @Autowired
    private RoleService roleService;

    /**
     * 跳转到列表页面
     *
     * @return
     */
    @RequestMapping("/torolelist")
    @RequiresPermissions("/role/torolelist")
    public String torolelist() {
        return "userpermission//role/role-list";
    }

    /**
     * 跳转到角色添加页面
     *
     * @return
     */
    @RequestMapping("/add")
    @RequiresPermissions("/role/torolelist")
    public String toadd(Role role, Model model) {
        model.addAttribute("role", role);
        return "userpermission/role/edit";
    }

    /**
     * 根据前台传值id查询编辑角色，返回编辑页面
     *
     * @param role
     * @param model
     * @return
     */
    @RequestMapping("/edit")
    @RequiresPermissions("/role/torolelist")
    public String toedit(Role role, Model model) {
        Role role1 = roleService.findById(role);
        model.addAttribute("role", role1);
        return "userpermission/role/edit";
    }

    @RequestMapping("/menuchoose")
    @RequiresPermissions("/role/torolelist")
    public String toMenuChoose(Role role, Model model) {
        //查询已关联权限回显

        //前台传入角色ID
        model.addAttribute("roleId", role.getId());
        return "userpermission/menu/choose";
    }

}
